/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test_system.controller;

import test_system.menu.*;
import test_system.parser.*;
import test_system.questions.TestWrapper;

/**
 *
 * @author root
 */
public class TestController {

    TestWrapper test;

    public void startTest() {
        StringBuffer testData = new ParserCSV().parseFile("/home/serji/Documents/qq.txt");
        test = new ParseRefactor(testData).createTest();
        Menu menu = new test_system.menu.Menu(test);
        String[] userAnswers = menu.runTestDialog();
        boolean[] userResult = checkUserAnswer(userAnswers);
        menu.markOutput(userResult);
    }

    private boolean[] checkUserAnswer(String[] stringRes) {
        boolean[] checkedAnswers = new boolean[stringRes.length];
        for (int index = 0; index < stringRes.length; index++) {
            if (test.getQuestion(index).getClassName().equals("TextAnswerQuestion")) {
                checkedAnswers[index] = test.getQuestion(index).getRigthAnswer().toString().equals(stringRes[index]);
            } else {
                checkedAnswers[index] = test.getQuestion(index).getAnswerById(new Integer(stringRes[index]) - 1).isRight();
            }
        }        
        return checkedAnswers;
    }
    
}
